package at.main.util;

import at.main.android.Manager;
import at.main.android.Player;
import at.main.android.VolumeControl;

public class ManagerAudio {
	// Notice String
	public String notice = "Do You Want To Enable Sound";

	// Volume
	public static int iVolume = 100;

	// Manager Player Sound
	public Player player;
	public Player playerBG;
	// Constructor SoundScreen

	public ManagerAudio() {

	}

	// Load Sound Method
	public void loadSound(String sName, int iLoop) {
		try {
			String in = "/sound/" + sName + ".mid";
			player = Manager.createPlayer(in, "audio/midi");
			player.realize();
			VolumeControl volume = (VolumeControl) player
					.getControl("VolumeControl");
			volume.setLevel(iVolume);
			player.setLoopCount(iLoop);
			player.prefetch();
			
			//DB:
			System.out.println("Duong dan = " + in);
		} catch (Exception e) {
			e.printStackTrace();
			System.out.println("Không Load được Sound...");
		}
	}

	// Method PlaySound
	public void playSound() {
		try {
			player.start();			
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	// Method Stop Sound
	public void stopSound() {
		try {
			player.stop();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	public void loadSoundBG(String sName, int iLoop) {
		try {
			String in = "/sound/" + sName + ".mid";
			playerBG = Manager.createPlayer(in, "audio/midi");
			playerBG.realize();
			VolumeControl volume = (VolumeControl) playerBG
					.getControl("VolumeControl");
			volume.setLevel(iVolume);
			playerBG.setLoopCount(iLoop);
			playerBG.prefetch();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	// Method PlaySound
	public void playSoundBG() {
		try {
			playerBG.start();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	// Method Stop Sound
	public void stopSoundBG() {
		try {
			playerBG.stop();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
